package com.sgb.businessmodule.view.ui.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.ViewGroup;

import com.sgb.businessmodule.BR;
import com.sgb.businessmodule.R;
import com.sgb.businessmodule.databinding.ItemTabChildBinding;
import com.sgb.businessmodule.entity.PickFilterEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.ResolutionUtil;

import java.util.List;

public class BusinessChildTabAdapter extends BaseRecycleAdapter<PickFilterEntity> {

    private String name = "全部";

    public BusinessChildTabAdapter(Context context, List<PickFilterEntity> data) {
        super(context, R.layout.item_tab_child, data);
    }

    @Override
    public void convert(ItemViewHolder holder, PickFilterEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemTabChildBinding binding = (ItemTabChildBinding) holder.getmBinding();

        if (!TextUtils.isEmpty(entity.getName()) && entity.getName().length() > 4) {
            binding.tvTabItem.setText(entity.getName().substring(0, 4) + "...");
        } else {
            binding.tvTabItem.setText(entity.getName());
        }

        if (entity.getName().equals(name)) {
            binding.tvTabItem.setSelected(true);
        } else {
            binding.tvTabItem.setSelected(false);
        }
    }

    public void setCurrentSelected(String name) {
        this.name = name;
        notifyDataSetChanged();
    }
}
